package com.doone.telmarket.service;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.springframework.stereotype.Service;

@Service("imageChecker")
public class ImageChecker {

	/*缩略图高度下限*/
	public static final int SMALL_IMAGE_HEIGHT_LT = 55;
	/*缩略图高度上限*/
	public static final int SMALL_IMAGE_HEIGHT_GT = 75;
	/*缩略图宽度下限*/
	public static final int SMALL_IMAGE_WIDTH_LT = 80;
	/*缩略图宽度上限*/
	public static final int SMALL_IMAGE_WIDTH_GT = 100;
	/*LOGO图高度下限*/
	public static final int BIG_IMAGE_HEIGHT_LT = 167;
	/*LOGO图高度上限*/
	public static final int BIG_IMAGE_HEIGHT_GT = 200;
	/*LOGO图宽度下限*/
	public static final int BIG_IMAGE_WIDTH_LT = 170;
	/*LOGO图宽度上限*/
	public static final int BIG_IMAGE_WIDTH_GT = 250;

	public String checkImage(File[] file) {

		BufferedImage bi;
		try {
			bi = ImageIO.read(file[0]);
			int height = bi.getHeight();
			int width = bi.getWidth();
			if (SMALL_IMAGE_HEIGHT_LT > height || SMALL_IMAGE_HEIGHT_GT < height || SMALL_IMAGE_WIDTH_LT > width
					|| SMALL_IMAGE_WIDTH_GT < width)
				return "增值业务的缩略图尺寸不合法";
			bi = ImageIO.read(file[1]);
			height = bi.getHeight();
			width = bi.getWidth();
			if (BIG_IMAGE_HEIGHT_LT > height || BIG_IMAGE_HEIGHT_GT < height || BIG_IMAGE_WIDTH_LT > width
					|| BIG_IMAGE_WIDTH_GT < width)
				return "增值业务的LOGO图尺寸不合法";
			return "S";
		} catch (IOException e) {
			e.printStackTrace();
			return "F";
		}
	}
}
